//
//  ZXTabBarController.m
//  qianke
//
//  Created by ZX on 2017/6/23.
//  Copyright © 2017年 ZX. All rights reserved.
//

#import "ZXTabBarController.h"
#import "ZXNavigationController.h"
#import "ZXTabBar.h"
#import "ViewController.h"
#import "platformTaskController.h"
#import "myTaskController.h"
#import "ZZmessageController.h"
#import "shenheController.h"
#import "ZZptrwPDController.h"
#import "myViewController.h"
@interface ZXTabBarController ()<UITabBarControllerDelegate>
@end

@implementation ZXTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;

    [self setupTabBar];
    [self setupItemAttrs];
    ViewController * vc1 = [ViewController new];
    vc1.title = @"我的任务";
    vc1.tabBarItem.image = [UIImage imageNamed:@"wdrw_hui"];
    vc1.tabBarItem.selectedImage = [UIImage imageNamed:@"wdrw_lan"];
    
    
    ZZmessageController * vc3 = [ZZmessageController new];
    vc3.title = @"消息";
    vc3.tabBarItem.image = [UIImage imageNamed:@"xiaoxi_hui"];
    vc3.tabBarItem.selectedImage = [UIImage imageNamed:@"xiaoxi_lan"];
    
    myViewController* vc4 = [myViewController new];
    vc4.title = @"我";
    vc4.tabBarItem.image = [UIImage imageNamed:@"wo_hui"];
    vc4.tabBarItem.selectedImage = [UIImage imageNamed:@"wo_lan"];
    
    
    ZXNavigationController * nav = [[ZXNavigationController alloc]initWithRootViewController:vc1];
    ZXNavigationController * nav3 = [[ZXNavigationController alloc]initWithRootViewController:vc3];
    ZXNavigationController * nav4 = [[ZXNavigationController alloc]initWithRootViewController:vc4];
    [self addChildViewController:nav];
    my_AppDelegate.isHasQX = YES;
     if (my_AppDelegate.assignO) {
         ZZptrwPDController * vc2 = [ZZptrwPDController new];
         vc2.title = @"平台任务";
         vc2.tabBarItem.image = [UIImage imageNamed:@"ptrw_hui"];
         vc2.tabBarItem.selectedImage = [UIImage imageNamed:@"ptrw_lan"];
         ZXNavigationController * nav2 = [[ZXNavigationController alloc]initWithRootViewController:vc2];
         [self addChildViewController:nav2];
     }else{
         platformTaskController * vc2 = [platformTaskController new];
         vc2.title = @"平台任务";
         vc2.tabBarItem.image = [UIImage imageNamed:@"ptrw_hui"];
         vc2.tabBarItem.selectedImage = [UIImage imageNamed:@"ptrw_lan"];
         ZXNavigationController * nav2 = [[ZXNavigationController alloc]initWithRootViewController:vc2];
         [self addChildViewController:nav2];
     }
    if (my_AppDelegate.auditR) {
        shenheController* vc5 = [shenheController new];
        vc5.title = @"审核";
        vc5.tabBarItem.image = [UIImage imageNamed:@"shenhe_hui"];
        vc5.tabBarItem.selectedImage = [UIImage imageNamed:@"shenhe_lan"];
        ZXNavigationController * nav5 = [[ZXNavigationController alloc]initWithRootViewController:vc5];
        [self addChildViewController:nav5];
    }
    [self addChildViewController:nav3];
    [self addChildViewController:nav4];

}

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    NSUInteger i = tabBarController.selectedIndex;
    [dic setObject:[NSString stringWithFormat:@"%lu",(unsigned long)i] forKey:@"selectedIndexStr"];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"selectedIndexStr" object:nil userInfo:dic];
    NSLog(@"%lu",(unsigned long)tabBarController.selectedIndex);
}
- (void)setupTabBar
{
    [self setValue:[[ZXTabBar alloc] init] forKeyPath:@"tabBar"];
}
- (void)setupItemAttrs
{
    UITabBarItem *item = [UITabBarItem appearance];
    NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
    normalAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:tabbarfontNumber];
    normalAttrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    [item setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
    
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSForegroundColorAttributeName] = baseLittleBlueColor;
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
